package io.renren.modules.yckj.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.yckj.dao.ProjectDao;
import io.renren.modules.yckj.dto.ProjectDTO;
import io.renren.modules.yckj.entity.ProjectEntity;
import io.renren.modules.yckj.service.ProjectService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 检测项目表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2025-04-16
 */
@Service
public class ProjectServiceImpl extends CrudServiceImpl<ProjectDao, ProjectEntity, ProjectDTO> implements ProjectService {

    @Override
    public QueryWrapper<ProjectEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        String name = (String) params.get("name");
        String cateName = (String) params.get("cateName");
        Object cateId = params.get("cateId");
        Object status = params.get("status");
        Object recommend = params.get("recommend");

        QueryWrapper<ProjectEntity> wrapper = new QueryWrapper<>();

        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.eq(ObjectUtil.isAllNotEmpty(status), "status", status);
        wrapper.eq(ObjectUtil.isAllNotEmpty(recommend), "recommend", recommend);
        wrapper.eq(ObjectUtil.isAllNotEmpty(cateId), "cate_id", cateId);
        wrapper.like(StrUtil.isNotBlank(name), "name", name);
        wrapper.like(StrUtil.isNotBlank(cateName), "cate_name", cateName);

        return wrapper;
    }


    @Override
    public List<ProjectDTO> getProjectListByMachineId(Map<String, Object> params) {
        List<ProjectEntity> entityList = baseDao.getProjectListByMachineId(params);
        return ConvertUtils.sourceToTarget(entityList, ProjectDTO.class);
    }
}